package com.portal.innovation.sysController;


import com.portal.innovation.utils.PageUtils;
import com.portal.innovation.common.R;
import com.portal.innovation.pojo.DictionaryConfig;
import com.portal.innovation.service.DictionaryConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;

@RestController
@RequestMapping("dictionary")
public class DictionaryConfigController {

    @Autowired
    private DictionaryConfigService dictionaryConfigService;

    @PostMapping("list")
    public R save(@RequestBody HashMap params) {
        PageUtils page = dictionaryConfigService.queryPage(params);
        return R.ok().put("page", page);
    }

    @PostMapping("save")
    public R save(@RequestBody DictionaryConfig dictionaryConfig) {
        dictionaryConfigService.save(dictionaryConfig);
        return R.ok();
    }

    @DeleteMapping("delete")
    public R save(@RequestBody Integer[] ids) {
        dictionaryConfigService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    @PostMapping("update")
    public R update(@RequestBody DictionaryConfig dictionaryConfig) {
        dictionaryConfigService.updateById(dictionaryConfig);
        return R.ok();
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        DictionaryConfig config = dictionaryConfigService.getById(id);
        return R.ok().put("config", config);
    }
}
